# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=hunspell-en
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2019.10.06
pkgrel=1
pkgdesc="Hunspell dictionaries (mingw-w64)"
arch=('any')
url="https://wordlist.sourceforge.io/"
license=('LGPL' 'custom:scowl')
makedepends=("unzip")
optdepends=(${MINGW_PACKAGE_PREFIX}-hunspell)
source=(https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_US-large-$pkgver.zip
        https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_AU-large-$pkgver.zip
        https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_CA-large-$pkgver.zip
        https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_GB-large-$pkgver.zip)
sha256sums=('cf18cf28ec0e0b1ca0e0b99fe223860f7777e8ca5358d98343cbed010f1ff5a3'
            '7a69d0531cf0635edf7fd0b2e6dfa1131212fe377ed007d03202612addf7f3a7'
            'de40608c09d68682243e0c3da49b70adf1feba146d18bdb03df823c4b389b11a'
            '4a24d57f40366b88836c9fd900a3aacb33b4e5cc0e05aac6abdfb580ef7ee977')

build() {
  /bin/true
}

package() {
  cd "$srcdir"
  install -dm755 ${pkgdir}${MINGW_PREFIX}/share/hunspell
  install -m644 en_*.dic en_*.aff ${pkgdir}${MINGW_PREFIX}/share/hunspell

  pushd ${pkgdir}${MINGW_PREFIX}/share/hunspell/
    en_GB_aliases="en_AG en_BS en_BW en_BZ en_DK en_GH en_HK en_IE en_IN en_JM en_NA en_NG en_NZ en_SG en_TT en_ZA en_ZW"
    for lang in $en_GB_aliases; do
      ln -s en_GB-large.aff $lang.aff
      ln -s en_GB-large.dic $lang.dic
    done

    en_AU_aliases="en_AU"
    for lang in $en_AU_aliases; do
      ln -s en_AU-large.aff $lang.aff
      ln -s en_AU-large.dic $lang.dic
    done

    en_US_aliases="en_PH en_US"
    for lang in $en_US_aliases; do
      ln -s en_US-large.aff $lang.aff
      ln -s en_US-large.dic $lang.dic
    done
    larges="en_CA en_GB"
    for lang in $larges; do
      mv $lang-large.aff $lang.aff
      mv $lang-large.dic $lang.dic
    done
  popd

  # the symlinks
  install -dm755 ${pkgdir}${MINGW_PREFIX}/share/myspell/dicts
  pushd ${pkgdir}${MINGW_PREFIX}/share/myspell/dicts
    for file in ${pkgdir}${MINGW_PREFIX}/share/hunspell/*; do
      ln -sv ${pkgdir}${MINGW_PREFIX}/share/hunspell/$(basename $file) .
    done
  popd

  # docs
  install -dm755 ${pkgdir}${MINGW_PREFIX}/share/doc/$_realname
  install -m644 README_en_??-large.txt ${pkgdir}${MINGW_PREFIX}/share/doc/$_realname

  # licenses
  install -D -m644 README_en_AU-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_AU
  install -D -m644 README_en_US-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_US
  install -D -m644 README_en_CA-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_CA
  install -D -m644 README_en_GB-large.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/Copyright_en_GB
}
